<?php
//php接口的写法，php访问mysql数据库的基本步骤,获取用户

//1 连接数据库服务器：  mysql_connect("服务器名称","用户名","密码");or die("前面语句执行不成功后返回的信息".mysql_error());
//.mysql_error() 这个函数的意思是什么原因导致前面的sql语句执行失败
$a = array(
	0 => "22",
	1 => "23",
	2 => "26",
	3 => "28",
	4 => "23",
	5 => "26",
	6 => "28",
	7 => "36",
	8 => "38",
	9 => "68",
);
$lian = array(2 => array('01', '90', '12', '23', '34', '45', '56', '67', '78', '89'));

$c = array_intersect($a, $lian['2']);

var_dump($c);

$a = '50286';
$pos = array(0 => 0);

//第三位与其它数字组成的2位组合
$arr = str_split($a);

$c = getNoLianCombinationToStringPos1($arr, $pos);
echo "<br>c=";
var_dump($c);

function getNoLianCombinationToStringPos1($arr, $pos) {
	$cnt = 0;
	if (count($pos) <= 2) {
		//5星2连1位，或者5星2连2位，当中的指标满足其中一个*或者*两个
		foreach ($pos as $key => $val) {
			for ($i = 0; $i < count($arr); $i++) {
				if ($i == $val) {
					continue;
				}
				if (isNotConsecutive($arr[$val], $arr[$i])) {
					$cnt++;
				}
			}
		}

	}
	return $cnt;
}

function isNotConsecutive($a, $b) {
	// 0369
	switch ($a) {
	case 0:
		return $b == 3 || $b == 5 || $b == 7;
	case 1:
		return $b == 4 || $b == 6 || $b == 8;
	case 2:
		return $b == 5 || $b == 7 || $b == 9;
	case 3:
		return $b == 0 || $b == 6 || $b == 8;
	case 4:
		return $b == 1 || $b == 7 || $b == 9;
	case 5:
		return $b == 0 || $b == 2 || $b == 8;
	case 6:
		return $b == 1 || $b == 3 || $b == 9;
	case 7:
		return $b == 0 || $b == 2 || $b == 4;
	case 8:
		return $b == 1 || $b == 3 || $b == 5;
	case 9:
		return $b == 2 || $b == 4 || $b == 6;
	}

	return false;
}
